<!DOCTYPE mapper
	PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
	"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${visitName}">
	<!--查询结果集 -->
	<select id="select" parameterType="${modebeanPkgNameFull}"
		resultType="${modebeanPkgNameFull}">
	select
	<#list columns as column>
		<#if column_has_next>
 		${column.column_name},
 		<#else>
 		${column.column_name}
 		</#if>
	</#list>
		from
		${table.tableName}
		<where>
			1=1
<#list columns as column>
	<#if column.isPk == true>
			<if test="${column.column_name} != null and ${column.column_name} != ''">
				<![CDATA[ and ${column.column_name} = ${r"#{"}${column.column_name}:${column.jdbc_type}} ]]>
			</if>
	<#else>
		<#if column.jdbc_type?index_of("TIME")!=-1>
			<if test="${column.column_name} != null and ${column.column_name} != ''">
		<![CDATA[ and ${column.column_name} = to_date(${r"#{"}${column.column_name}:${column.jdbc_type}},'yyyy-mm-dd hh24:mi:ss') ]]>
			</if>
			<#if column.remarks??>
				<#if column.remarks?index_of("<区域>")!=-1>
				<if test="${column.column_name}Min != null">
			<![CDATA[ and ${column.column_name} >= to_date(${r"#{"}${column.column_name}Min:${column.jdbc_type}},'yyyy-mm-dd hh24:mi:ss') ]]>
				</if>		
				<if test="${column.column_name}Max != null">
			<![CDATA[ and ${column.column_name} <= to_date(${r"#{"}${column.column_name}Max:${column.jdbc_type}},'yyyy-mm-dd hh24:mi:ss') ]]>
				</if>	
	 			</#if>	
	 		</#if>
		<#else>
			<if test="${column.column_name} != null and ${column.column_name} != ''">
		<![CDATA[ and instr(${column.column_name} ,${r"#{"}${column.column_name}:${column.jdbc_type}})]]>
			</if>
		</#if>
	</#if>
</#list>
		</where>
	</select>

	<select id="selectOne" parameterType="${modebeanPkgNameFull}"
		resultType="${modebeanPkgNameFull}">
	select
	<#list columns as column>
		<#if column_has_next>
 		${column.column_name},
 		<#else>
 		${column.column_name}
 		</#if>
	</#list>
		from
		${table.tableName}
		<where>
			1=1
<#list columns as column>
	<#if column.isPk == true>
			<if test="${column.column_name} != null and ${column.column_name} != ''">
				<![CDATA[ and ${column.column_name} = ${r"#{"}${column.column_name}:${column.jdbc_type}} ]]>
			</if>
	<#else>
		<#if column.jdbc_type?index_of("TIME")!=-1>
			<if test="${column.column_name} != null and ${column.column_name} != ''">
		<![CDATA[ and ${column.column_name} = to_date(${r"#{"}${column.column_name}:${column.jdbc_type}},'yyyy-mm-dd hh24:mi:ss') ]]>
			</if>
			<#if column.remarks??>
				<#if column.remarks?index_of("<区域>")!=-1>
				<if test="${column.column_name}Min != null">
			<![CDATA[ and ${column.column_name} >= to_date(${r"#{"}${column.column_name}Min:${column.jdbc_type}},'yyyy-mm-dd hh24:mi:ss') ]]>
				</if>		
				<if test="${column.column_name}Max != null">
			<![CDATA[ and ${column.column_name} <= to_date(${r"#{"}${column.column_name}Max:${column.jdbc_type}},'yyyy-mm-dd hh24:mi:ss') ]]>
				</if>	
	 			</#if>	
	 		</#if>
		<#else>
			<if test="${column.column_name} != null and ${column.column_name} != ''">
		<![CDATA[ and instr(${column.column_name} ,${r"#{"}${column.column_name}:${column.jdbc_type}})]]>
			</if>
		</#if>
	</#if>
</#list>
		</where>
	</select>

	<select id="selectByPriKey" parameterType="java.lang.Object"
		resultType="${modebeanPkgNameFull}">
	select
	<#list columns as column>
		<#if column_has_next>
 		${column.column_name},
 		<#else>
 		${column.column_name}
 		</#if>
	</#list>
		from
		${table.tableName}
		<where>
			1=1
	<#if table.pks[0].column_name??>
		and ${table.pks[0].column_name}=${r"#{"}${table.pks[0].column_name}:${table.pks[0].jdbc_type}}
	</#if>
		</where>
	</select>
	
	<!--新增 -->
	<insert id="insert" parameterType="${modebeanPkgNameFull}">
	  <![CDATA[
	insert into ${table.tableName}
	(
	<#list columns as column>
		<#if column_has_next>
 		${column.column_name},
 		<#else>
 		${column.column_name}
 		</#if>
	</#list>
	) values (
	<#list columns as column>
		<#if column_has_next>
 		${r'#{'}${column.column_name}:${column.jdbc_type}},
 		<#else>
 		${r'#{'}${column.column_name}:${column.jdbc_type}}
 		</#if>
	</#list>	
	 ) 
	    ]]>
	</insert>

	<!--修改 -->
	<update id="update" parameterType="${modebeanPkgNameFull}">
	  <![CDATA[
	update  ${table.tableName}
	set 
	<#list columns as column>
		<#if column_has_next>
 		${column.column_name}=${r'#{'}${column.column_name}:${column.jdbc_type}},
 		<#else>
 		${column.column_name}=${r'#{'}${column.column_name}:${column.jdbc_type}}
 		</#if>
	</#list>	
	where
	1=1 and
<#if table.pks[0].column_name??>
	${table.pks[0].column_name}=${r'#{'}${table.pks[0].column_name}:${table.pks[0].jdbc_type}}
</#if>
	    ]]>
	</update>
 
	<!--刪除 -->
	<delete id="deleteById" parameterType="java.lang.String">
	delete from
	 ${table.tableName}
	where 
	<#if table.pks[0]??>
		${table.pks[0].column_name} in
		<foreach item="item" index="index" collection="list" open="(" separator="," close=")">  
  			${r'#{item}'}  
 		</foreach>
	</#if>
	</delete>	
	
</mapper>
	